package com.weixin.paleituo.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.weixin.paleituo.R;
import com.weixin.paleituo.base.BaseRecycleAdapter;
import com.weixin.paleituo.bean.OrderDetailsBean;
import com.weixin.paleituo.help.RecycleViewHolder;
import com.weixin.paleituo.util.UIUtils;

import java.text.DecimalFormat;
import java.util.ArrayList;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * 订单详情界面 商品列表查看
 * 这里只做展示效果，没有任何页面交互
 *
 * @author fengzhen
 * @version v1.0, 2018/4/8
 */
public class GoodsListOrderRecycleAdapter extends BaseRecycleAdapter<OrderDetailsBean.StoreListBean.GoodsListBean> {

    private DecimalFormat format = new DecimalFormat("#0.00");

    public GoodsListOrderRecycleAdapter(Context context, ArrayList<OrderDetailsBean.StoreListBean.GoodsListBean> datas) {
        super(context, datas, R.layout.item_goods_list_order);
    }

    @Override
    protected void setData(RecycleViewHolder holder, OrderDetailsBean.StoreListBean.GoodsListBean s, int position) {
        ViewHolder viewHolder = (ViewHolder) holder;
        OrderDetailsBean.StoreListBean.GoodsListBean model = mDatas.get(position);
        Glide.with(mContext)
                .load(model.getListUrl())
                .into(viewHolder.mImgGoodsItemGoodsListOrder);
        viewHolder.mTvNameItemGoodsListOrder.setText(model.getGoodsName());
        viewHolder.mTvInfoItemGoodsListOrder.setText(model.getGoodsSpecsInfo());
        viewHolder.mTvCountEachItemGoodsListOrder.setText(String.format(mContext.getString(R.string.string_x), model.getGoodsSalenum()));
        viewHolder.mTvPriceItemGoodsListOrder.setVisibility(View.VISIBLE);
//        viewHolder.mLinearVipItemGoodsListOrder.setVisibility(View.GONE);
        if (model.getGoodsPrice() <= 0) {
            viewHolder.mTvPriceItemGoodsListOrder.setVisibility(View.GONE);
//            viewHolder.mTvPriceItemGoodsListOrder.setText("￥待定");
        } else {
            viewHolder.mTvPriceItemGoodsListOrder.setVisibility(View.VISIBLE);
            viewHolder.mTvPriceItemGoodsListOrder.setText(String.format(mContext.getString(R.string.string_pay), format.format(Double.valueOf(model.getGoodsPrice()))));
        }
    }

    @Override
    public RecycleViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        return new ViewHolder(UIUtils.inflate(mContext, R.layout.item_goods_list_order, parent, false));
    }

    static class ViewHolder extends RecycleViewHolder {
        @BindView(R.id.img_goods_item_goods_list_order)
        ImageView mImgGoodsItemGoodsListOrder;
        @BindView(R.id.tv_name_item_goods_list_order)
        TextView mTvNameItemGoodsListOrder;
        @BindView(R.id.tv_info_item_goods_list_order)
        TextView mTvInfoItemGoodsListOrder;
        @BindView(R.id.tv_price_item_goods_list_order)
        TextView mTvPriceItemGoodsListOrder;
        //        @BindView(R.id.tv_current_price_item_goods_list_order)
//        TextView mTvCurrentPriceItemGoodsListOrder;
//        @BindView(R.id.tv_original_price_item_goods_list_order)
//        TextView mTvOriginalPriceItemGoodsListOrder;
//        @BindView(R.id.linear_vip_item_goods_list_order)
        LinearLayout mLinearVipItemGoodsListOrder;
        @BindView(R.id.tv_count_each_item_goods_list_order)
        TextView mTvCountEachItemGoodsListOrder;

        ViewHolder(View view) {
            super(view);
            ButterKnife.bind(this, view);
        }
    }
}
